package com.xrit.quartz;


import com.xrit.constant.RedisMessageConstant;
import com.xrit.utils.QiNiuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

/**
 * 清除垃圾图片的工作类
 */
public class CleanImgJob {

    @Autowired
    private JedisPool jedisPool;

    /**
     * 清除
     */
    public void doClean(){
        System.out.println("调用了："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        Jedis jedis = jedisPool.getResource();
        Set<String> sdiff = jedis.sdiff(RedisMessageConstant.SETMEAL_PIC_RESOURCES, RedisMessageConstant.SETMEAL_PIC_DB_RESOURCES);
        QiNiuUtils.removeFiles(sdiff.toArray(new String[]{}));
        jedis.del(RedisMessageConstant.SETMEAL_PIC_RESOURCES, RedisMessageConstant.SETMEAL_PIC_DB_RESOURCES);
        jedis.close();
    }
}
